#!/bin/bash
########## cffr investment  测试版本部署脚本--new-plutus2 
set -x 
date_stamp=`date "+%Y-%m-%d %H:%M:%S"`
date1=`date "+%Y-%m-%d-%H-%M-%S"`
exec &>>/home/ubuntu/cff-investment/deploy-investment-$date1.log
echo "123+123" 
#jar地址
SERVCER_JAR=earning-farm-investment-0.0.1-SNAPSHOT.jar
#日志名称
LOG_NAME=cff-investment.log
#进入对应目录
DIR="/home/ubuntu/cff-investment"
cd $DIR ;pwd
#输出信息
echo '---------------------------------------'
echo $DIR
#创建项目jar包工程目录
if [ ! -d $DIR/jar ];then
  mkdir -p $DIR/jar
fi
#创建备份目录
echo $date_stamp
#杀死java进程
_pid=`ps -ef | grep java | grep $SERVCER_JAR |awk '{print $2}'`
echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
[ !  -n "$_pid" ] && pkill -f earning-farm-investment-0.0.1-SNAPSHOT.jar 

pkill -f earning-farm-investment-0.0.1-SNAPSHOT.jar

#echo $DIR/$SERVCER_JAR
cp $DIR/$SERVCER_JAR  $DIR/jar
cp $DIR/$SERVCER_JAR  $DIR/jar1
cp $DIR/$SERVCER_JAR  $DIR/jar2
cp $DIR/$SERVCER_JAR  $DIR/jar3
cp $DIR/$SERVCER_JAR  $DIR/jar4


branch_v=$1
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_311
export JAVA=$JAVA_HOME/bin/java
export PATH=${JAVA_HOME}/bin:$PATH

echo '---------------------------------------java path'
#source /home/ubuntu/cff-investment/.env

echo "deploy mhusdc"
nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC  -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps      \
  -Dspring.profiles.active=prod   \
  -Dserver.port=8280  \
  -Dcff-name=USDC         \
  -Dsubscription.service.url=172.31.40.23:8180    \
  -Drisk_type=1     \
  -Dvalue_type=1          \
  -Dapy_type=2  \
  -Dserver.servlet.context-path=/mhusdc    \
  -Dnet_work=mainnet     \
  -Dspring.datasource.username=test-investment -Dspring.datasource.password='test-cff@!@#YeeZ'     \
  -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm?useUnicode=true&characterEncoding=utf-8"     \
  -Dlogging.file.path=/home/ubuntu/cff-investment  \
  -Dserver.address=172.31.40.23    \
  /home/ubuntu/cff-investment/jar1/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/mhusdc/cff-investment.log  2>&1  &  

sleep 5
echo "deploy musdc"
nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC  -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps        \
  -Dspring.profiles.active="prod"  \
  -Dserver.port=8380 \
  -Dcff_name=USDC   \
  -Dsubscription.service.url=172.31.40.23:8180  \
  -Drisk_type=0  \
  -Dserver.servlet.context-path=/musdc  \
  -Dnet_work=mainnet    \
  -Dorigin_ration=1000000   \
  -Dspring.datasource.username=test-investment -Dspring.datasource.password='test-cff@!@#YeeZ'   \
  -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_musdc?useUnicode=true&characterEncoding=utf-8"     \
  -Dlogging.file.path=/home/ubuntu/cff-investment         \
  -Dserver.address=172.31.40.23         \
  /home/ubuntu/cff-investment/jar1/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/musdc/cff-investment.log  2>&1  & 

sleep 5
echo "deploy mheth"
nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps        \
  -Dspring.profiles.active="prod" \
  -Dcff_name=ETH  \
  -Dserver.port=8580  \
  -Dsubscription.service.url=172.31.40.23:8180     \
  -Drisk_type=1  \
  -Dfee_ratio=0.01   \
  -Dapy_type=3  \
  -Dserver.servlet.context-path=/mheth   \
  -Dnet_work=mainnet   \
  -Dorigin_ration=1000000 \
  -Dspring.datasource.username=test-investment -Dspring.datasource.password='test-cff@!@#YeeZ'      \
  -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_heth?useUnicode=true&characterEncoding=utf-8"     \
  -Dlogging.file.path=/home/ubuntu/cff-investment       \
  -Dserver.address=172.31.40.23       \
  /home/ubuntu/cff-investment/jar2/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/mheth/cff-investment.log  2>&1  &

sleep 5
echo "deploy meth"
nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps        \
  -Dspring.profiles.active="prod"  \
  -Dcff_name=ETH   \
  -Dserver.port=8780  \
  -Dsubscription.service.url=172.31.40.23:8180 \
  -Drisk_type=0   \
  -Dserver.servlet.context-path=/meth \
  -Dnet_work=mainnet                \
  -Dspring.datasource.username=test-investment -Dspring.datasource.password='test-cff@!@#YeeZ'       \
  -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_meth?useUnicode=true&characterEncoding=utf-8"     \
  -Dlogging.file.path=/home/ubuntu/cff-investment        \
  -Dserver.address=172.31.40.23         \
  /home/ubuntu/cff-investment/jar3/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/meth/cff-investment.log  2>&1  &

sleep 5
echo "deploy mwbtc"
nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps       \
  -Dspring.profiles.active="prod" \
  -Dcff_name=WBTC \
  -Dserver.port=8880 \
  -Drisk_type=0   \
  -Dsubscription.service.url=172.31.40.23:8180  \
  -Dserver.servlet.context-path=/mwbtc \
  -Dnet_work=mainnet  \
  -Dorigin_ration=100000000 \
  -Dspring.datasource.username=test-investment -Dspring.datasource.password='test-cff@!@#YeeZ'   \
  -Dspring.datasource.url="jdbc:mysql://172.31.40.23:3307/earningfarm_mwbtc?useUnicode=true&characterEncoding=utf-8"   \
  -Dlogging.file.path=/home/ubuntu/cff-investment         \
  -Dserver.address=172.31.40.23         \
  /home/ubuntu/cff-investment/jar4/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/mwbtc/cff-investment.log  2>&1  &

sleep 5

s_pid=`ps -ef | grep java | grep $SERVCER_JAR |awk '{print $2}'`
send_weixin_v2  "【部署推送】\n【$date_stamp】\n【cff/earning-farm】\n【investment/后端/】\n【测试环境】【new-plutos2/18.166.174.50】\n【$branch_v】 分支部署完成, 进程pid：$s_pid , from  部署脚本。 "

